package com.lefevre.cms.bean.membershipCard;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 会员卡
 *
 * @author Lefevre
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("membership_card")
@Entity
@Table(name = "membership_card", indexes = {@Index(name = "membership_card_1_idx", columnList = "createDate")})
public class MembershipCard implements Serializable {
    private static final long serialVersionUID = -4891301979499383115L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.INPUT)
    private Long id;

    /**
     * 名称
     **/
    @Column(length = 190)
    @TableField("`name`")
    private String name;

    /**
     * 副标题
     **/
    @Column(length = 190)
    @TableField("subtitle")
    private String subtitle;

    /**
     * 角色Id
     **/
    @Column(length = 50)
    @TableField("userRoleId")
    private String userRoleId;

    /**
     * 最低销售价 精度为12位，小数点位数为2位
     **/
    @Column(precision = 12, scale = 2)
    @TableField(value = "lowestPrice", numericScale = "2")
    private BigDecimal lowestPrice;

    /**
     * 最高销售价 精度为12位，小数点位数为2位
     **/
    @Column(precision = 12, scale = 2)
    @TableField(value = "highestPrice", numericScale = "2")
    private BigDecimal highestPrice;

    /**
     * 最低积分
     **/
    @TableField("lowestPoint")
    private Long lowestPoint;

    /**
     * 最高积分
     **/
    @TableField("highestPoint")
    private Long highestPoint;

    /**
     * 创建时间
     **/
    @Temporal(TemporalType.TIMESTAMP)
    @TableField("createDate")
    private Date createDate = new Date();

    /**
     * 简介
     **/
    @Lob
    @TableField("introduction")
    private String introduction;

    /**
     * 规格集合
     **/
    @Transient
    @TableField(exist = false)
    private List<Specification> specificationList = new ArrayList<>();

    /**
     * 说明标签集合
     **/
    @Transient
    @TableField(exist = false)
    private List<String> descriptionTagList = new ArrayList<>();

    /**
     * 说明标签 JSON格式List<String>
     **/
    @Lob
    @TableField("descriptionTagFormat")
    private String descriptionTagFormat;

    /**
     * 排序
     **/
    @TableField("sort")
    private Integer sort = 0;

    /**
     * 状态 1:上架  2.下架 3.规格下架(本状态不存储) 11. 上架标记删除  12. 下架标记删除
     **/
    @TableField("state")
    private Integer state = 1;

    public void addSpecification(Specification specification) {
        this.specificationList.add(specification);
    }

}
